package com.tencent.ied.bk.handler.impl;

import com.tencent.ied.bk.entity.SearchAbstractInfo;
import com.tencent.ied.bk.handler.Handler;
import com.tencent.ied.bk.handler.HandlerObject;

import java.util.Arrays;

/**
 * @author chen_yu
 * @date 2021/3/11 6:39
 */
public class ContainsKeyWordHandler implements Handler {


    /**
     * 包含关键字设置逻辑
     *
     * @param handlerObject 处理对象
     */
    @Override
    public void handle(HandlerObject handlerObject) {
        String strKeyWord = handlerObject.getStrKeyWord();
        //设置包含的数量
        for (SearchAbstractInfo searchAbstractInfo : handlerObject.getSearchAbstractInfoList()) {
            long nums = Arrays.stream(searchAbstractInfo.getWords()).filter(s -> s.contains(strKeyWord) && !s.equals(strKeyWord)).count();
            searchAbstractInfo.setSearchContainsKeyWordCountInContent((int) nums);
        }

    }
}
